
import './assets/main.css'

import { createPinia } from 'pinia'
import { createApp } from 'vue'
import ECharts from 'vue-echarts'
import 'echarts' 
import 'echarts-liquidfill'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import { v4 as uuidv4 } from 'uuid'
import {useTokenInfoStore} from '@/stores/login-Pinia'
import { onMounted } from 'vue'



import App from './App.vue'
import router from './router'

const pinia = createPinia()
const app = createApp(App)

app.use(pinia)
app.use(router)
app.mount('#app')
app.component('ECharts',ECharts)
app.component('uuidv4',uuidv4)  
app.use(ElementPlus, {
    locale: zhCn,
  })
  
  onMounted(resToreState())
  // 当用户点击浏览器刷新时，把本地存储的token赋值给pinia。防止pinia数据丢失
function resToreState(){
  const storedRefreshToken = localStorage.getItem('tokenInfo')
  if(storedRefreshToken !== ""){
    let tokenInfoStore = useTokenInfoStore()
    tokenInfoStore.$state = JSON.parse(storedRefreshToken)
  }else{
    router.push("/")
  }
}


